/*
    The MIT License

    Copyright (c) 2010 IFMO/GameDev Studio

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	Animation track :
-----------------------------------------------------------------------------*/

class EAnimTrack : public IAnimTrack {
	public:
								EAnimTrack		( void );
								~EAnimTrack		( void );
	
		virtual void			SetFPS			( float fps ) { frames_per_second = fps; }
		virtual float			GetFPS			( void ) const { return frames_per_second; }
	
		virtual void			SetTrackSize	( uint curve_num, uint length );
		virtual uint			GetTrackLength	( void ) const;
		virtual uint			GetCurveNum		( void ) const;
		virtual uint			GetCurveByName	( const EString &name ) const;
		
		virtual void			SetCurveParent	( uint child_curve, uint parent_curve );
		virtual uint			GetCurveParent	( uint child_curve ) const;
		virtual void			SetCurveName	( uint curve, const EString &name );
		virtual EString			GetCurveName	( uint curve ) const;
		
		virtual void			SetSample		( uint curve, uint sample, const EPoint &pos, const EQuaternion &orient );
		
		virtual void			GetSample		( uint curve, int sample,							EPoint &pos, EQuaternion &orient, bool repeat ) const;
		virtual void			LerpSamples		( uint curve, int sample0, int sample1, float frac, EPoint &pos, EQuaternion &orient, bool repeat ) const;
		virtual void			LerpSamples		( uint curve, float frac_sample,					EPoint &pos, EQuaternion &orient, bool repeat ) const;
		virtual void			GetSampleAtTime	( uint curve, float time,							EPoint &pos, EQuaternion &orient, bool repeat ) const;
	
		virtual IPxAnimTrack	Clone			( void ) const;
		virtual void			WriteXML		( rapidxml::xml_node<> *xnode ) const;
		virtual void			ReadXML			( rapidxml::xml_node<> *xnode );
		
		//	animation blending :
		virtual void			BuildAnimFrame			( const IPxTriMesh mesh, float frac_sample, bool repeat );
		virtual void			AddTransform			( uint curve, const EVector &translate, const EQuaternion &rotate );
		virtual EMatrix		*	BuildGlobalMatricies	( const IPxTriMesh mesh );
		
		void					CheckCompatibilityWithMeshJoints	( const IPxTriMesh mesh );
		
	protected:
		float	frames_per_second;
		
		struct EAnimSample {
			EPoint		translate;
			EQuaternion	orient;
		};
		
		struct Curve {
			Curve () : parent_id(-1) {}
			EString			name;
			uint			parent_id;
			std::vector<EAnimSample>	samples;
		};
		
		std::vector<Curve> curves;
		
		std::vector<EMatrix>		matricies;
		std::vector<EAnimSample>	frame;
	};
	
	

